using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Husb.Util;
using Husb.Util.Enum;
using CentralOffice.File.Data;
using CentralOffice.File.BusinessActions;

using FileTable = CentralOffice.File.Data.FileDataSet.FileDataTable;
using FileRow = CentralOffice.File.Data.FileDataSet.FileRow;

namespace CentralOffice.WebClient.Files
{
    public partial class FileUpdate : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                string id = HttpContext.Current.Request.QueryString["id"];
                FileRow file = CentralOffice.File.BusinessActions.Files.GetById(new Guid(id));

                if (!file.IsAttachmentsNull() && file.Attachments.Length > 0)
                {
                    string[] attachments = file.Attachments.Split(SiteConstants.CommonSeparatorChar);
                    Repeater2.DataSource = attachments;
                    Repeater2.DataBind();
                }
                else
                {
                    attachment.Visible = false;
                }
            }
        }

        protected void Repeater1_ItemCreated(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                RepeaterItem item = e.Item;
                HyperLink anchor = e.Item.Controls[1] as HyperLink;
                string path = (String)e.Item.DataItem;

                SiteUtil.GenernateDownloadHyperLink(anchor, path);
                //achor.Text = path.Substring(path.LastIndexOf(System.IO.Path.AltDirectorySeparatorChar) + 1);
                //achor.NavigateUrl = SiteUtil.GetDownloadFileName(path);
            }
        }

        protected void Repeater2_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            RepeaterItem item = e.Item;
            HyperLink anchor = e.Item.Controls[0] as HyperLink;
            string path = (String)e.Item.DataItem;

            SiteUtil.GenernateDownloadHyperLink(anchor, path);
        }
    }
}
